package code06_数组;
import java.util.Scanner;
/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月17日10:11
 */
public class Test02_数组的遍历 {

    public static void main(String[] args) {
        test03();
    }

    public static void test01() {
        int[] nums = {1, 3, 5, 7, 9};
        // 返回数组中元素的数量
        System.out.println("数组的长度:" + nums.length);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "\t");
        }

        String names[] = {"admin", "jack", "tom", "lucy", "alex", "alice"};
        for (int i = 0; i < names.length; i++) {
            System.out.print(names[i] + "\t");
        }
    }

    public static void test02() {
        Scanner sc = new Scanner(System.in);
        int[] nums = new int[5];
        for (int i = 0; i < nums.length; i++) {
            System.out.print("请输入下标为" + i + "的元素的值:");
            nums[i] = sc.nextInt();
        }
        System.out.println("数据录入完毕,数组元素的数据如下:");
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "\t");
        }
    }

    public static void test03() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入声明的数组元素的数量:");
        int length = sc.nextInt();
        int[] nums = new int[length];
        for (int i = 0; i < nums.length; i++) {
            System.out.print("请输入下标为" + i + "的元素的值:");
            nums[i] = sc.nextInt();
        }
        System.out.println("数据录入完毕,数组元素的数据如下:");
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "\t");
        }
    }

}
